package edu.lit.B180401;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Student {
    private int id;
    private String name;
    private String stuno;


    //SQLite存储
    SQLiteDatabase db;

    public  int  insertBySQLite(Context context){
        DBHelper helper=new DBHelper(context);
        ContentValues values=new ContentValues();
        db=helper.getWritableDatabase();
        values.put(DBUtil.STUINFO_ID,id);
        values.put(DBUtil.STUINFO_NAME,name);
        values.put(DBUtil.STUINFO_STUNO,stuno);
        long number=db.insert(DBUtil.TABLE_STUINFO,null,values);
        return (int)number;
    }

    public int selectByStunoBySQLite(Context context){
        DBHelper helper=new DBHelper(context);
        ContentValues values=new ContentValues();
        db = helper.getReadableDatabase();
        Cursor cursor=null;
        cursor = db.query(DBUtil.TABLE_STUINFO, null, DBUtil.STUINFO_STUNO+"=?", new String[]{stuno+""},null, null, null);
        if (cursor.getCount() != 0){
            while (cursor.moveToNext()){
                name = cursor.getString(cursor.getColumnIndex(DBUtil.STUINFO_NAME));
                id = cursor.getInt(cursor.getColumnIndex(DBUtil.STUINFO_ID));
                stuno = cursor.getString(cursor.getColumnIndex(DBUtil.STUINFO_STUNO));
            }
        }
        return  0;
    }

    /*public int delBySQLite(Context context){
        DBHelper helper=new DBHelper(context);
        ContentValues values=new ContentValues();
        db = helper.getWritableDatabase();
        int number = db.delete(DBUtil.TABLE_STUINFO, DBUtil.STUINFO_ID+"=?", new String[]{id+""});
        return  number;
    }*/

    /*public int updateBySQLite(Context context){
        DBHelper helper=new DBHelper(context);
        db = helper.getWritableDatabase();
        ContentValues values=new ContentValues();
        values.put(DBUtil.STU_PHONE, phone);
        values.put(DBUtil.STU_PWD, pwd);
        values.put(DBUtil.STU_EMAIL, email);
        int number = db.update(DBUtil.TABLE_NAME, values, DBUtil.STU_NAME+"=?",new String[]{name+""});
        return number;
    }*/


    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", stuno='" + stuno + '\'' +
                ", db=" + db +
                '}';
    }

    public Student() {
    }

    public Student(int id, String name, String stuno) {
        this.id = id;
        this.name = name;
        this.stuno = stuno;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getStuno() {
        return stuno;
    }

    public void setStuno(String stuno) {
        this.stuno = stuno;
    }
}
